//
//  MyFundDetailViewController.m
//  Umoney
//
//  Created by zwz on 16/8/31.
//  Copyright © 2016年 zhangwz. All rights reserved.
//

#import "MyFundDetailViewController.h"

@interface MyFundDetailViewController ()
{
    NSString *PID;
    NSString *UID;
    NSArray *res;
}

@end

@implementation MyFundDetailViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    
    self.PrincipalMoney.text = self.myprincialmoney;
    self.InterestMoney.text = self.myinterestmoney;
    self.TotalMoney.text =self.mytotalmoney;
    self.TotalTime.text = self.mytotaltime;
    self.RemainTime.text = self.myremaintime;
    self.ProductName.text = self.myproductname;
    self.pid.text = PID;

}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

-(instancetype)initWithCode:(NSString *)code andUser:(NSString *)uid
{
    PID = code;
    UID = uid;
    _ready = @"no";
    //得到网络数据
    
    NSString *urlString = [NSString stringWithFormat:@"http://23.106.134.160/umoney/search_myinvest_detail.php?uid=%@&pid=%@",UID,PID];
    
    NSURLSessionConfiguration *config = [NSURLSessionConfiguration ephemeralSessionConfiguration];
    config.timeoutIntervalForRequest = 30.0f;
    config.timeoutIntervalForResource = 60.0f;
    NSURLSession *session = [NSURLSession sessionWithConfiguration:config];
    NSURLSessionTask *task = [session dataTaskWithURL:[NSURL URLWithString:urlString] completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
        res = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:nil];
        
    }];
    [task resume];
    
    while (!res) {
    }
    
    for (NSDictionary *x in res) {
        
        self.myprincialmoney = [x valueForKey:@"pricipalmoney"];
        self.myinterestmoney = [x valueForKey:@"interestmoney"];
        float total = [self.myprincialmoney floatValue] + [self.myinterestmoney floatValue];
        self.mytotalmoney = [NSString stringWithFormat:@"%.2f",total];
        
        self.mytotaltime = [x valueForKey:@"totaltime"];
        NSString *Passtime = [x valueForKey:@"passtime"];
        int remain = [self.mytotaltime intValue] - [Passtime intValue];
        self.myremaintime = [NSString stringWithFormat:@"%d",remain];
        
        self.myproductname = [x valueForKey:@"pname"];
        
        
        _ready = @"ready";
    }

    

    return self;
}



/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
